home *** CD-ROM | disk | FTP | other *** search
- Path: gaia.ns.utk.edu!mbk
- From: mbk@caffeine.engr.utk.edu (Matt Kennel)
- Newsgroups: comp.lang.c++
- Subject: Re: Creating operator= for *pointers* to objects??
- Date: 12 Mar 1996 18:45:12 GMT
- Organization: University of Tennessee, Knoxville and Oak Ridge National Laboratory
- Message-ID: <4i4gno$psa@gaia.ns.utk.edu>
- References: <Do4KtH.MK@mv.mv.com> <4i4aqd$e2b@fsgi01.fnal.gov>
- Reply-To: kennel@msr.epm.ornl.gov
- NNTP-Posting-Host: caffeine.engr.utk.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- David Sachs (b91926@fsgi01.fnal.gov) wrote:
- : bnb@curtech.com (Brian Ballard) writes:
-
-
-
- : >I'm trying to find a way to create an assignment (or copy) operator
- : >which I can use to apply to pointers to object. For example, say I have
- : >a class hierarchy that looks like:
-
- : > |--- B
- : > A ---|--- C
- : > |--- D
-
- : >Millions of these objects can potentially be created and scrapped every
- : >few minutes so, in order to improve performance and reduce memory
- : >fragmentation, every class in the hierarchy has their new/delete operators
- : >overloaded to use a handful of "pre-built" objects in the freestore.
- : >Pretty standard stuff.
-
- : >Because exact duplicates of an instantiated object can (and must) exist,
- : >class A has a refCount member which allows me to keep track of how many
- : >copies of a duplicated object exist out there, so I don't pull the rug
- : >out from under an object that is still being used.
-
- : >In general, megabytes worth of network packets are stored in a file, which
- : >get read in by this software and are wrapped up in one of the above derived
- : >classes (B, C, or D) depending upon the type of packet. This creates a
- : >virtual "list" of sorts where I have an iterator which walks through the
- : >file, returning objects of type B/C/D.
-
- : >Basically, I'd like to be able to do this:
-
- : >{
- : > A* start = NULL;
- : > A* temp = NULL;
-
- : > start = mStream->GetPacketAtOffset(0L); // This might return an object B*
- : > temp = start; // I need this to call my oper=
- : > while ( temp = mStream->GetNextPacket(temp)) // GetNextPacket automatically
- : > bla bla bla // 'delete's first A* temp
-
- : >...
- : >}
-
- : >Not a big deal to it this way, but it's easy to forget over the long haul
- : >that these steps need to be taken. It's much easier to do a simple pointer
- : >assignment which guarantees that every pointer to an object is accounted for.
-
-
- : >OK.... a bit much content for such an easy question....
-
-
- : Since operators cannot be overloaded for build-in types, you may
- : wish to define a "smart pointer" class to refer to your objects.
-
- To me, this sounds like an excellent application for an automatic
- garbage collector. A garbage collector will automatically free those
- objects which are not being pointed to by any other live object. You
- use conventional pointers as you always would.
-
- There is a free one on ftp://parcftp.xerox.com/pub/gc, I believe,
- and I have seen Usenet advertisements for commercial products for
- Unix and Windows.
-
- cheers
- Matt
-
-
- : --
- : ***** Listen Americans, the IRS is your taxer, the IRS is one. *****
- : David Sachs - Fermilab, HPPC MS369 - P. O. Box 500 - Batavia, IL 60510
- : Voice: 1 708 840 3942 Deparment Fax: 1 708 840 3785
-